MV_GIGE_ForceIpEx

MV_GIGE_ForceIpEx

Force camera network parameter, including IP address, subnet mask, default gateway.

API Definition

int MV_GIGE_ForceIpEx(
  void            *handle,
  unsigned int    nIP,
  unsigned int    nSubNetMask,
  unsigned int    nDefaultGateWay
);

Parameters

handle

[IN] Device handle, which is returned by MV_CC_CreateHandle or MV_CC_CreateHandleWithoutLog.

nIP

[IN] IP address

nSubNetMask

[IN] Subnet mask

nDefaultGateWay

[IN] Default gateway

Return Value

Return MV_OK(0) on success, and return Error Code on failure.

Remarks

  • This function is supported only by GigEVision cameras.

  • After forcing camera network parameters (including IP address, subnet mask, default gateway), you should create the device handle again.

  • If device is in DHCP status, after calling this API to force camera network parameter, the device will restart.

The following sample code is for reference only.

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //Enumerate all the corresponding devices of specified transport protocol in the subnet.
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //Selected the first online device in the search result, and create device handle.
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //Set device IP address
    unsigned int nIP = 0x0a0f0636; //10.15.6.54
    unsigned int nSubNetMask = 0xffffff00; //255.255.255.0
    unsigned int nDefaultGateWay = 0x0a0f06fe; //10.15.6.254
    nRet = MV_GIGE_ForceIpEx(m_handle, nIP, nSubNetMask, nDefaultGateWay);
    if (MV_OK != nRet)
    {
        printf("error: ForceIpEx fail [%x]\n", nRet);
        return;
    } 

    //...Other processes.

    //Destroy handle, release resource
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}

MV_GIGE_ForceIpEx

Force camera network parameter, including IP address, subnet mask, default gateway.

API Definition

int MV_GIGE_ForceIpEx(
  void            *handle,
  unsigned int    nIP,
  unsigned int    nSubNetMask,
  unsigned int    nDefaultGateWay
);

Parameters

handle

[IN] Device handle, which is returned by MV_CC_CreateHandle or MV_CC_CreateHandleWithoutLog.

nIP

[IN] IP address

nSubNetMask

[IN] Subnet mask

nDefaultGateWay

[IN] Default gateway

Return Value

Return MV_OK(0) on success, and return Error Code on failure.

Remarks

  • This function is supported only by GigEVision cameras.

  • After forcing camera network parameters (including IP address, subnet mask, default gateway), you should create the device handle again.

  • If device is in DHCP status, after calling this API to force camera network parameter, the device will restart.

The following sample code is for reference only.

#include "MvCameraControl.h"

void main()
{
    int nRet = -1;
    void* m_handle = NULL;

    //Enumerate all the corresponding devices of specified transport protocol in the subnet.
    unsigned int nTLayerType = MV_GIGE_DEVICE | MV_USB_DEVICE;
    MV_CC_DEVICE_INFO_LIST m_stDevList = {0};
    int nRet = MV_CC_EnumDevices(nTLayerType, &m_stDevList);
    if (MV_OK != nRet)
    {
        printf("error: EnumDevices fail [%x]\n", nRet);
        return;
    }

    int i = 0;
    if (m_stDevList.nDeviceNum == 0)
    {
        printf("no camera found!\n");
        return;
    }

    //Selected the first online device in the search result, and create device handle.
    int nDeviceIndex = 0;

    MV_CC_DEVICE_INFO m_stDevInfo = {0};
    memcpy(&m_stDevInfo, m_stDevList.pDeviceInfo[nDeviceIndex], sizeof(MV_CC_DEVICE_INFO));

    nRet = MV_CC_CreateHandle(&m_handle, &m_stDevInfo);

    if (MV_OK != nRet)
    {
        printf("error: CreateHandle fail [%x]\n", nRet);
        return;
    }

    //Set device IP address
    unsigned int nIP = 0x0a0f0636; //10.15.6.54
    unsigned int nSubNetMask = 0xffffff00; //255.255.255.0
    unsigned int nDefaultGateWay = 0x0a0f06fe; //10.15.6.254
    nRet = MV_GIGE_ForceIpEx(m_handle, nIP, nSubNetMask, nDefaultGateWay);
    if (MV_OK != nRet)
    {
        printf("error: ForceIpEx fail [%x]\n", nRet);
        return;
    } 

    //...Other processes.

    //Destroy handle, release resource
    nRet = MV_CC_DestroyHandle(m_handle);
    if (MV_OK != nRet)
    {
        printf("error: DestroyHandle fail [%x]\n", nRet);
        return;
    }
}